<!DOCTYPE html>
<html lang="en">

<include file="CommonSidebar:common-head"/>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/css/common.css">
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">套装书列表</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <span class="btn  btn-primary" onclick='AddTZBookShow()'>添加套装书列表</span>
            </div>
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                    <tr>
                                        <th style="text-align:center">书籍套装名</th>
                                        <th style="text-align:center">套装ISBN</th>
                                        <th style="text-align:center" width="30%">书籍套装丛书名</th>
                                        <th style="text-align:center">套装状态</th>
                                        <th style="text-align:center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <foreach name="DATA" item="v" key="k">
                                        <tr class="odd gradeX">
                                            <td style="vertical-align:middle;">{$v.TITLE}</td>
                                            <td>{$v.ISBN}</td>
                                            <td>{$v.TITLE_C}</td>
                                            <if condition="$v.booknum == 0">
                                                <if condition="$v.notOKnum gt 0">
                                                    <td style="vertical-align:middle;color: red">
                                                        <a target="_blank"
                                                           href="{:U('Book/EditBookIndex')}?ID={$v.book_id}">
                                                            已成套，可成套数{$v.notOKnum}.点击马上完善套装书库存信息
                                                        </a>
                                                    </td>
                                                    <else/>
                                                    <td style="vertical-align:middle;color:blue">
                                                        已经完善成套信息,部分书籍没库存，请等待库存齐备即可成套
                                                    </td>
                                                </if>
                                                <else/>
                                                <td style="vertical-align:middle;">
                                                    本套书籍成套本书{$v.BOOK_NUM},还差{$v.booknum}本未完善
                                                </td>
                                            </if>
                                            <td style="vertical-align:middle;">
                                                <if condition="$v.book_id != null">
                                                    <a href="{:U('CtBookList')}?ID={$v.ID}"
                                                       class="btn btn-warning btn-xs"
                                                       title="Edit">查看详情</a>
                                                    <a onclick="AddTZBookShow('{$v.book_id}','{$v.BOOK_NUM}','{$v.ID}')"
                                                       class="btn btn-warning btn-xs"
                                                       title="Edit">编辑</a>
                                                    <else/>
                                                    <a href="{:U('Book/AddTzBookList')}?ID={$v.ID}"
                                                       class="btn btn-danger btn-xs"
                                                       target="_blank"
                                                       title="Edit">完善套装</a>
                                                </if>


                                                <a href="javascript:void(0)" onclick="Delete('{$v.ID}',$(this))"
                                                   class="btn btn-danger btn-xs" title="Delete">删除</a>
                                            </td>

                                        </tr>
                                    </foreach>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>

                    </div>
                </div>


            </div>
        </div>

    </div>
</div>

<!--添加套装书籍-->
<div id="ADDTZBOOK" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm">
        <form action="{:U('AddTzBookList')}" class="form-horizontal" method="get">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title text-center">添加/编辑套装列表</h4>
                </div>
                <div class="modal-body">
                    <div class="container-fluid">
                        <div class="row">
                            <input id="ID" type="hidden" name="ID" value="">
                            <input id="BOOK_ID" type="hidden" name="BOOK_ID" value="">

                            <div class="col-xs-12">
                                <label>ISBN</label>
                                <input class="form-control" id="ISBN" name="ISBN" required>
                            </div>
                            <div class="col-xs-12">
                                <label>套装书名</label>
                                <input class=" form-control" id="TITLE" name="TITLE" required>
                            </div>
                            <div class="col-xs-12">
                                <label>丛书名</label>
                                <input class=" form-control" id="TITLE_C" name="TITLE_C" required>
                            </div>
                            <div class="col-xs-12">
                                <label>套装书本书</label>
                                <input type="number" class=" form-control" id="BOOK_NUM" name="BOOK_NUM" value="10">
                            </div>
                            <div class="col-xs-6 modal-footer">
                                <button id="Button" type="submit" class="btn btn-block btn-primary">添加</button>
                            </div>
                            <div id="GoBook" class="col-xs-6 modal-footer" hidden>
                                <span onclick="GoBook()" class="btn btn-block btn-primary">前往编辑书籍</span>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>
<!--添加套装书籍-->

<!--查看位置-->
<div id="WZModal" class="modal fade bs-example-modal-sm" data-backdrop='static' tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true" style="font-size:35px">&times;</span></button>
                <h3 class="modal-title text-center">成套书籍位置单</h3>
            </div>
            <div class="modal-body" style="padding-top:0px;padding-bottom:5px;">
                <div class="row" style="height:530px;overflow-y:scroll;">
                    <div class=" spell-list"
                         style="height:100%; background:#f0f0f0; overflow-y:scroll; overflow-x:hidden; -webkit-overflow-scrolling:touch">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="panel-body">
                                    <div class="dataTable_wrapper">
                                        <table class="table table-striped table-bordered table-hover"
                                               id="dataTables-example1">
                                            <thead>
                                            <tr>
                                                <th style="text-align: center">书名</th>
                                                <th style="text-align: center">仓库</th>
                                                <th style="text-align:center">书架</th>
                                                <th style="text-align:center">书柜</th>
                                            </tr>
                                            </thead>
                                            <tbody id="WZDATA">

                                            </tbody>
                                        </table>
                                    </div>
                                    <!-- /.table-responsive -->
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--查看位置-->

<include file="CommonSidebar:common-script"/>
<script src="__ROOT__/Application/Admin/Public/js/jquery.datetimepicker.js"></script>
<!-- DataTables JavaScript -->
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="__ROOT__/Application/Admin/Public/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->


<script type="text/javascript" src="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.js?v=3"></script>
<link rel="stylesheet" href="__ROOT__/Application/Admin/Public/LoadPading/LoadPading.css" type="text/css"
      media="screen"/>


<script>
    $(document).ready(function () {
        $('#dataTables-example').DataTable({
            responsive: true
        });
    });
</script>
<script>

    //前往编辑书籍
    function GoBook() {
        var ID = $('#BOOK_ID').val();
        window.location.href = "{:U('Book/EditBookIndex')}?ID=" + ID;
    }

    //添加书籍显示弹窗
    function AddTZBookShow(book_id, book_num, ID) {
        $.post("{:U('GetBookToID')}",
                {ID: book_id},
                function (data) {
                    if (data) {
                        $('#ID').val(ID);
                        $('#BOOK_ID').val(book_id);
                        $('#ISBN').val(data['ISBN']);
                        $('#TITLE').val(data['TITLE']);
                        $('#TITLE_C').val(data['TITLE_C']);
                        $('#BOOK_NUM').val(book_num);

                        $('#ISBN').attr("readonly", "readonly");
//                        $('#TITLE').attr("readonly", "readonly");
//                        $('#TITLE_C').attr("readonly", "readonly");
                        $('#Button').html('编辑');

                        $('#GoBook').show();
                    } else {
                        $('#ID').val('');
                        $('#BOOK_ID').val('');
                        $('#ISBN').val('');
                        $('#TITLE').val('');
                        $('#TITLE_C').val('');

                        $('#ISBN').removeAttr("readonly");
                        $('#TITLE').removeAttr("readonly");
                        $('#TITLE_C').removeAttr("readonly");
                        $('#Button').html('添加');
                        $('#GoBook').hide();
                    }
                });
        $('#ADDTZBOOK').modal('show');
    }


    //删除操作
    function Delete(ID, elem) {
        if (confirm("确认删除？")) {
            $.post("{:U('TzBookListDel')}",
                    {ID: ID},
                    function (data) {
                        if (data) {
                            alert('删除成功');
                            elem.parent().parent().remove();
                        } else {
                            alert('删除失败');
                        }
                    });
        }
    }

    //    查看书籍位置
    function ckwz(ID) {
        $.post("{:U('GetTZBookWZ')}",
                {ID: ID},
                function (data) {
                    console.log(data);
                    var html = '';
                    $("#WZDATA").html("");
                    for (var i = 0; i < data.length; i++) {
                        console.log(data[i]);
                        html += "<tr class='odd gradeX'> ";
                        html +=
                                "<td class='enter' style='text-align:center'> " +
                                data[i]['TITLE'] +
                                "</td> " +
                                "<td class='enter' style='text-align:center'> "
                                + data[i]['c_P']
                                + data[i]['c_C']
                                + data[i]['c_Z']
                                + data[i]['c_ADDRESS']
                                + data[i]['c_NAME'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'> "
                                + data[i]['j_CODE'] +
                                "</td> " +
                                "<td class='center' style='text-align:center'> "
                                + data[i]['g_CODE'] +
                                "</td> ";
                        html += "</tr>";
                    }
                    $("#WZDATA").append(html);

                    $("#WZModal").modal("show");
                });
    }

    //出库操作
    function ck(ISBN, TZID, WE_ID, elem) {
        if (confirm("确认出库？")) {
            $.post("{:U('TzCk')}",
                    {WE_ID: WE_ID, TZID: TZID, ISBN: ISBN},
                    function (data) {
                        switch (parseInt(data)) {
                            case 0:
                                alert('出库失败');
                                break;
                            case 1:
                                alert('出库成功');
                                elem.parent().parent().css('color', 'red');
                                break;
                            case 2:
                                alert('系统检测不存在套装书籍，请添加书籍信息');
                                window.location.href = "{:U('Book/AddBookIndex')}";
                                break;
                            default:
                                alert('系统检测已经存在套装书籍，请添加入库位置即可');
                                window.location.href = "{:U('Book/index')}?ISBN=" + data;
                                break;
                        }
                    });
        }
    }
</script>
</body>

</html>
